#include "Blockqueue.hpp"
#include "Thread.hpp"

using namespace ThreadModule;
using namespace BlockQueueModule;

void *Productor(Blockqueue<int> &bq)
{
    int data = 10;
    while (true)
    {
        // sleep(2); // 先让消费者进入等待
        printf("生产者生产了一个data: %d\n", data);
        bq.Equeue(data);
        data++;
    }
}
void *Consumer(Blockqueue<int> &bq)
{
    while (true)
    {
        sleep(2);
        int data = 0;
        bq.Pop(&data);
        printf("consumer get a data: %d\n", data);
    }
}

int main()
{
    Blockqueue<int> *bq = new Blockqueue<int>();
    Thread<Blockqueue<int>> p1(Productor, *bq);
    // Thread<Blockqueue<int>> p2(Productor, *bq);
    Thread<Blockqueue<int>> c1(Consumer, *bq);
    // Thread<Blockqueue<int>> c2(Consumer, *bq);
    // Thread<Blockqueue<int>> c3(Consumer, *bq);

    p1.Start();
    // p2.Start();

    c1.Start();
    // c2.Start();
    // c3.Start();

    p1.Join();
    // p2.Join();

    c1.Join();
    // c2.Join();
    // c3.Join();
    delete bq;
    return 0;
}